<!DOCTYPE html>
<html>
<head>

    <title>ajax请求restful接口</title>


<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>

</head>

<body>


<input type="button" id="index"  value="index">
<input type="button" id="create" value="create">
<input type="button" id="save"  value="save">
<input type="button" id="read"  value="read">
<input type="button" id="edit"  value="edit">
<input type="button" id="update"  value="update">
<input type="button" id="delete"  value="delete">
<script>
    $(document).ready(function(){
      $("#index").click(function(){

        $.ajax({
            'url' : "/news",
            'type' : "get",
            'data' : "",
            "dataType": "json",
            "success" : function(res){
                console.log(res);
            }
        })

      });

      $("#create").click(function(){

        $.ajax({
            'url' : "/news/create",
            'type' : "get",
            'data' : "",
            "dataType": "json",
            "success" : function(res){
                console.log(res);
            }
        })

        });

        $("#save").click(function(){

            $.ajax({
                'url' : "/news",
                'type' : "post",
                'data' : "",
                "dataType": "json",
                "success" : function(res){
                    console.log(res);
                }
            })

        });

        $("#read").click(function(){

            $.ajax({
                'url' : "/news/33",
                'type' : "get",
                'data' : "",
                "dataType": "json",
                "success" : function(res){
                    console.log(res);
                }
            })

        });

        $("#edit").click(function(){

            $.ajax({
                'url' : "/news/33/edit",
                'type' : "get",
                'data' : "",
                "dataType": "json",
                "success" : function(res){
                    console.log(res);
                }
            })

        });
        $("#update").click(function(){

            $.ajax({
                'url' : "/news/33",
                'type' : "put",
                'data' : "",
                "dataType": "json",
                "success" : function(res){
                    console.log(res);
                }
            })

        });
        $("#delete").click(function(){

            $.ajax({
                'url' : "/news/33",
                'type' : "delete",
                'data' : "",
                "dataType": "json",
                "success" : function(res){
                    console.log(res);
                }
            })

        });





    });
    </script>
<!-- 伪装put  delete 请求-->
<input type="button" id="post-to-put"  value="post-to-put"> 
<input type="button" id="post-to-delete"  value="post-to-delete">
<script>
$(document).ready(function(){
      $("#post-to-put").click(function(){

        $.ajax({
            'url' : "/news/33",
            'type' : "post",
            'data' : "_method=put",
            "dataType": "json",
            "success" : function(res){
                console.log(res);
            }
        })

      });

      $("#post-to-delete").click(function(){

        $.ajax({
            'url' : "/news/33",
            'type' : "post",
            'data' : "_method=delete",
            "dataType": "json",
            "success" : function(res){
                console.log(res);
            }
        })

        });

    });



</script>

</body>
</html>